-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add get_zones & create_zone REST API endpints #56
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really like it overall!! 💯 Some minor stylistic/formatting changes and we are good to go!! :)
@@ -1,9 +1,8 @@ | |||
<?php | |||
/** | |||
* @packae Zoninator/Rest | |||
* @package Zoninator/Rest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching this!
$this->translations = array( | ||
self::ZONE_NOT_FOUND => __( 'Zone not found', 'zoninator' ), | ||
self::INVALID_POST_ID => __( 'Invalid post id', 'zoninator' ), | ||
self::INVALID_ZONE_ID => __( 'Zone not found', 'zoninator' ), | ||
self::ZONE_ID_POST_ID_REQUIRED => __( 'post id and zone id required', 'zoninator' ), | ||
); | ||
|
||
$this->add_route( 'zones' ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great form here!
) ); | ||
} | ||
|
||
return new WP_REST_Response( $results, 200 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can also do return $this->ok( $results );
|
||
$zone = $this->instance->get_zone( $result[ 'term_id' ] ); | ||
|
||
return $this->created( $zone ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice created usage! :)
$slug = $this->_get_param( $request, 'slug', '' ); | ||
$description = $this->_get_param( $request, 'description', '', 'strip_tags' ); | ||
|
||
$result = $this->instance->insert_zone( $slug, $name, array( 'description' => $description ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool! Better if we split this into multiple lines (standard php practice on arrays with string keys, leave a comma in the array's end. Like so:
$result = $this->instance->insert_zone( $slug, $name, array(
'description' => $description,
) );
@@ -479,6 +547,11 @@ public function strip_slashes( $item ) { | |||
return stripslashes( $item ); | |||
} | |||
|
|||
public function strip_tags( $item ) { | |||
// see https://github.com/WP-API/WP-API/issues/1520 on why we do not use stripslashes directly |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update comment to be about strip_tags :)
This PR adds
get_zones
&create_zones
endpoints to the REST API.Endpoints
GET /zoninator/v1/zones
( get a list with all zones )POST /zoniantor/v1/zones
( create a new zone )Other
Changed permissions for
add_post_to_zone
toupdate
as it falls under editing a zone rather than creating one.